﻿/*  PandoraUnleashed
    An open source API for the Pandora music service
    Copyright © 2011 Saulius Milevicius

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PandoraUnleashed.Data
{
    class StationData
    {
        public Boolean allowAddMusic;
        public Boolean allowDelete;
        public Boolean allowRename;
        public String artUrl;
        public long dateCreated;
        public Boolean isQuickMix;
        public Boolean isShared;
        public Boolean requiresCleanAds;
        public String stationId;
        public String stationName;
        public String stationToken;
        public Boolean supportImpressionTargeting;
        public Boolean suppressVideoAds;

        /// <summary>
        /// Default constructor for station data
        /// </summary>
        /// <param name="stationToken">Stations token</param>
        /// <param name="stationId">Stations id</param>
        /// <param name="stationName">Stations name</param>
        /// <param name="dateCreated">Date station was created on</param>
        /// <param name="isQuickMix">Is this station a quick mix</param>
        /// <param name="isShared">Is this station shared</param>
        /// <param name="allowAddMusic">Are we allowed to add music to the station</param>
        /// <param name="allowRename">Are we allowed to rename the station</param>
        /// <param name="allowDelete">Are we allowed to delete the station</param>
        /// <param name="requiresCleanAds">Does the station require clean ads</param>
        /// <param name="suppressVideoAds">Are we suppressing video ads</param>
        /// <param name="supportImpressionTargeting">Do we support impression targetting</param>
        public StationData(String stationToken, String stationId, String stationName, long dateCreated, Boolean isQuickMix, Boolean isShared, Boolean allowAddMusic, Boolean allowRename, Boolean allowDelete, Boolean requiresCleanAds, Boolean suppressVideoAds, Boolean supportImpressionTargeting)
        {
            this.stationToken = stationToken;
            this.stationId = stationId;
            this.stationName = stationName;
            this.dateCreated = dateCreated;
            this.isQuickMix = isQuickMix;
            this.isShared = isShared;
            this.allowAddMusic = allowAddMusic;
            this.allowRename = allowRename;
            this.allowDelete = allowDelete;
            this.requiresCleanAds = requiresCleanAds;
            this.suppressVideoAds = suppressVideoAds;
            this.supportImpressionTargeting = supportImpressionTargeting;
            this.dateCreated = (long)((TimeSpan)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0))).TotalMilliseconds;
        }

        /// <summary>
        /// Default construction for station data
        /// </summary>
        /// <param name="stationToken">Stations token</param>
        /// <param name="artUrl">Station art url</param>
        public StationData(String stationToken, String artUrl)
        {
            this.stationToken = stationToken;
            this.artUrl = artUrl;
        }

        /// <summary>
        /// Create station data from a hashtable of json params
        /// </summary>
        /// <param name="json">Hashtable of json params</param>
        public StationData(Hashtable json)
        {
            this.stationToken = (String)json["stationToken"];
            this.stationId = (String)json["stationId"];
            this.stationName = (String)json["stationName"];
            if (json.ContainsKey("requiresCleanAds"))
                this.requiresCleanAds = (Boolean)json["requiresCleanAds"];
            else
                this.requiresCleanAds = false;
            if (json.ContainsKey("suppressVideoAds"))
                this.suppressVideoAds = (Boolean)json["suppressVideoAds"];
            else
                this.suppressVideoAds = false;
            if (((Hashtable)json["adAttributes"]).ContainsKey("supportImpressionTargeting"))
                this.supportImpressionTargeting = (Boolean)((Hashtable)json["adAttributes"])["supportImpressionTargeting"];
            else
                this.supportImpressionTargeting = false;
            this.dateCreated = (long)(double)((Hashtable)json["dateCreated"])["time"];
            this.isQuickMix = (Boolean)json["isQuickMix"];
            this.isShared = (Boolean)json["isShared"];
            this.allowAddMusic = (Boolean)json["allowAddMusic"];
            this.allowRename = (Boolean)json["allowRename"];
            this.allowDelete = (Boolean)json["allowDelete"];
            if (json.ContainsKey("artUrl"))
                this.artUrl = (String)json["artUrl"];
            else
                this.artUrl = "";
        }
    }
}
